<template>
  <Row class="layout-content-body">
    <dtable :columnsList="columns" v-model="dataAll"   :totals="total" read
    check  op  flowStatus
    @refresh="getall()"   @get="get"
    @delCheck="delCheck" :loading="loading"></dtable>
    <!-- <Modal title="采购单信息" v-model="editData" :mask-closable="false" class="editm" @on-ok="asyncOK" @on-cancel="asyncCancel">
      <Form ref="editForm" :model="formItem" :label-width="80" :rules="ruleValidate">
        <Form-item label="名称" prop="Name">
          <Input v-model="formItem.Name"  placeholder="请输入" :disabled="addid" @on-enter="asyncOK()"></Input>
        </Form-item>
        <Form-item label="数量" prop="Count">
          <Input v-model="formItem.Count"  number placeholder="请输入" @on-enter="asyncOK()"></Input>
        </Form-item>
        <Form-item label="金额" prop="Money">
          <Input v-model="formItem.Money" number placeholder="请输入" @on-enter="asyncOK()"></Input>
        </Form-item>
      </Form>
    </Modal> -->
  </Row>
</template>
<script>
import {timeFormat, 
        currency} from '@/common/filter'
import dtable from '../../components/table/etable.vue'//采用biztable
export default {
  data() {
    return {
      loading: false,//数据刷新遮罩层
      columns: [
        //多选框

        {
          title: '名称',
          key: 'Name',
          sortable: true
        },
        {
          title: '单位',
          key: 'DeptName',
          sortable: true
        },
        {
          title: '操作类型',
          key: 'Optype  ',
          sortable: true,
          render: (h, params) => {
            let str = ""
            switch (params.row.Optype) {
                case 0:
                    str = "添加"
                    break
                case 1:
                    str = "修改"
                    break
                case 2:
                    str = "删除"
                    break
                default:
                    str = "其他"
                }
            return h('span', {}, str);
          }
        },
        {
          title: '责任人',
          key: 'Creater',
          sortable: true
        },
        {
          title: '创建时间',
          key: 'Ctime',
          sortable: true,
          render: (h, params) => {
            return h('div', [
              h('strong', timeFormat(params.row.Ctime))
            ]);
          }
        },
      ],//表格样式
      dataAll: [],//表格数据来源
      dataShow: true,//是否显示表格数据查看表单
      editData: false,//显示编辑表单
      formItem: {
        Name: '',
        Count: 1,
        Money: 0
      },//数据编辑表单
      ruleValidate: {
        Name: [
          { required: true, message: '账号不能为空', trigger: 'blur' }
        ],
        Pname: [
          { required: true, message: '名称不能为空', trigger: 'blur' },
        ],
      },//数据编辑表单验证规则
      addid: true,//true为修改模式，false为添加模式
      role: [],
      org: [],
      total: 0,
      orderData: {
        edit: true,
        temp: ''
      }
    }
  },
  components: {
    dtable,
  },
  computed: {


  },
  watch: {},
  methods: {
    get(data) {
      this.orderData.order = data
      this.orderData.edit=false
      this.$router.push({
        name: '技术人员审批',
        params: {
          orderData: this.orderData
        }
      })
    }, 
    getall() {
      this.loading = true
      let data={
        busyName:"sf_engineer_instance"
      }
      this.$api.getAssetsbuyFinish(data).then(res => {
        if (!res.error) {
          console.log(res.Data)
          this.dataAll = res.Data
          if(this.total){
            this.total = (res.Data).length
          }
        } else {
          this.$Message.error(res.message)
        }
      })
      setTimeout(() => {
        this.loading = false;
      }, 500);
    },
    edit(index) {
      this.addid = true
      this.formItem = index
      this.editData = true
    },
    add() {
      this.addid = false
      this.$refs['editForm'].resetFields()
      this.editData = true
    },
    asyncOK() {
      this.$refs['editForm'].validate((valid) => {
        if (valid) {
          if (this.addid) {
            this.$api.updateAssetsbuy(this.formItem).then(res => {
              if (!res.error) {
                this.getall()
                this.$Message.success(res.message)
              } else {
                this.$Message.error(res.message, 4)
              }
            })
          } else if (!this.addid) {
            this.$api.addAssetsbuy(this.formItem).then(res => {
              if (!res.error) {
                this.getall()
                this.$Message.success(res.message)
              } else {
                this.$Message.error(res.message, 4)
              }
            })
          }
          setTimeout(() => {
            this.editData = false;
          }, 1000);
        } else {
          this.$Message.error('表单验证失败!');
        }
      })
      this.editData = false
      this.$refs['editForm'].resetFields()

    },
    asyncCancel() {
      this.getall()
      this.$refs['editForm'].resetFields()
    },
    del(row) {
      this.$api.deleteAssetsbuy(row).then(res => {
        if (!res.error) {
          this.getall()
          this.$Message.success(res.message)
        } else {
          this.$Message.error(res.message, 4)
        }
      })
    },
    delCheck(row) {
      this.$api.deleteUsers(row).then(res => {
        if (!res.error) {
          this.getall()
          this.$Message.success(res.message)
        } else {
          this.$Message.error(res.message, 4)
        }
      })
    },
    reset(row) {
      this.$api.ResetPwd(row).then(res => {
        if (!res.error) {
          this.getall()
          this.$Message.success(res.message)
        } else {
          this.$Message.error(res.message, 4)
        }
      })
    }

  },
  mounted() {
     this.getall()
  }
}
</script>
